package com.twu.biblioteca;

import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Iterator;

/**
 * Created by sahej on 6/14/14.
 */
public class AddBookToFile {
    static ArrayList<Book> availableBook=new ArrayList<Book>();
    private static void initializeList()
    {

        availableBook.add(new Book(1,"Far from the Madding Crowd","Thomas hardy",2000));
        availableBook.add(new Book(2,"The Merchant of Venice","William Shakespeare",1992));
        availableBook.add(new Book(3,"A Tale of Two Cities","Charles Dicken",1989));
        availableBook.add(new Book(4,"Gulliver's Travels","Jonathan Swift",1981));
        availableBook.add(new Book(5,"Discovery of India","Pt.Jawaharlal Nehru",1967));
        availableBook.add(new Book(6,"Pride and Prejudice","Jane Austen",1991));
        availableBook.add(new Book(7,"War and Peace","Leo Tolstoy",1967));
        availableBook.add(new Book(8,"Alice in Wonderland","Lewis Carrol",1994));
        availableBook.add(new Book(9,"Hamlet","Shakespeare",1991));
        availableBook.add(new Book(10,"Tom Sawyer","Mark Twain",1982));
        availableBook.add(new Book(11,"My experiments with Truth","Mahatma Gandhi",1997));
        availableBook.add(new Book(12,"Time Machine","H.G. Wells",2002));
        availableBook.add(new Book(13,"Mahabharata","Vyas",1971));
        availableBook.add(new Book(14,"Jungle Book","Rudyard Kipling",1999));
        availableBook.add(new Book(15,"Odyssey","Homer",2007));

    }
    public static void main(String args[]) throws Exception
    {
        initializeList();
        Iterator<Book> iterator = availableBook.iterator();
        try{

            FileOutputStream fout = new FileOutputStream("Book.ser");
            ObjectOutputStream oos = new ObjectOutputStream(fout);
            while (iterator.hasNext()) {
                Book b= iterator.next();
                oos.writeObject(b);
            }

            oos.close();
            System.out.println("Done");

        }catch(Exception ex){
            ex.printStackTrace();
        }

        FileOutputStream fout = new FileOutputStream("User.ser");
        ObjectOutputStream oos = new ObjectOutputStream(fout);
        oos.writeObject(new User("Sahej","sahej.makkar@gmail.com","9811525635","123-4567","hello123"));
        oos.writeObject(new User("Surbhi","surbhi@gmail.com","9718658816","435-6786","welcome12"));
        oos.writeObject(new User("Shiksha","shiksha@gmail.com","9718627126","456-6775","abc123"));

        oos.close();

        FileOutputStream f = new FileOutputStream("Transaction.ser");
        ObjectOutputStream oo = new ObjectOutputStream(f);
        oo.close();



    }
}
